[#ftl]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公司编辑</title> 
<script type="text/javascript" src="${base}/commonjs/jquery.upload.js" charset="utf-8"></script>
<script type="text/javascript">
var filePath2="${base}";
var actionUrl="/commerce/platUploadfile/storeFileAdd";
</script>
<script type="text/javascript" src="${base}/commonjs/ueditor/ueditor.config.js"></script> 
<script type="text/javascript" src="${base}/commonjs/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="${base}/commonjs/ueditor/lang/zh-cn/zh-cn.js"></script>
<css>
    <style type="text/css">
    .editor { width: 780px; height: 510px; float: left; }
    </style>
    <style>
    .mainImage{border-color:#393;border-style: solid solid solid solid;border-width: 3px !important;}
    .image-div{border:1px solid #cdcdcd;width:155px;height:155px;text-align: center;}
    .error {color: Red; font-size: 13px; margin-left: 5px; padding-left: 16px;}
    </style>
</css>
<script type="text/javascript">
    var editor = UE.getEditor('myEditor', {
        initialFrameWidth: 780,
        initialFrameHeight: 360,
        scaleEnabled:true
    });
    editor.ready(function () {
        editor.addListener('beforeInsertImage', function (t, arg) {     //侦听图片上传
            //将id赋值给相应的input                        
            $("#add_table").append("<input type='hidden' name='contentimageUrl' value='"
                +arg[0].src+"'>");
        })
    });

    //上传独立使用
    var _editor =  UE.getEditor('upload_ue');
    _editor.ready(function () {
        _editor.setDisabled();
        _editor.hide();
        _editor.addListener('afterUpfile', function (t, arg) {
            for(var i=0;i<arg.length;i++){
                $("#filelist").append("<li data-name='"+arg[i].original+"'><a href='${base}/"+arg[i].url+"' target='_black'>"+arg[i].original+"</a>"
                +" <a href='javascript:void(0)' onClick='deleteFile(this)'>删除</a><input type='hidden' name='fileId' value='"
                +arg[i].type+"'></li>");
            }
        })
    });
    
    //弹出文件上传的对话框
    function upFiles() {
        var myFiles = _editor.getDialog("attachment");
        myFiles.open();
    }
    //删除已上传的文件
    function deleteFile(param){
       var fileId=$(param).parent().find("input:eq(0)").attr("value");
       if($(param).parents("li").find("img:eq(0)").hasClass("mainImage")){
           $("#bannerId").val('');
           $("#bannerUrl").val('');
       }
       if($(param).parents("li").attr('data_type')==1){
           $("#logoId").val('');
           $("#logoUrl").val('');
       }
       $.ajax({
           url : "${base}/commerce/platUploadfile/delete",
           traditional:true,
           data:{"fileId":fileId},
           dataType: "json",
           success: function(data){ 
                var messages = extendMessages(data);                                                  
                if(messages.isAllSuccess())
                {
                    $(param).parents('li').remove();
                    
                    if($("#imglist li").length<=0){
                         $("#imglist").parent().height(0);
                    } 
                }
            },
            error:function(){
            }
        });       
    }

$(function(){
  getTodayTime();
//每隔一秒刷新一次
// setInterval("getTodayTime()",1000);
}); 
function getTodayTime(){
        var d = new Date();
        var vYear = d.getFullYear();
        var vMon = d.getMonth() + 1;
        var vDay = d.getDate();
        var hour=d.getHours();
        var minut=d.getMinutes();
        var secds=d.getSeconds();
        var today=vYear+(vMon<10 ? "-0" + vMon : "-"+vMon)+(vDay<10 ? "-0"+ vDay : "-"+vDay)
               +" "+(hour<10 ? "0" + hour : hour)
               +":"+(minut<10 ? "0" + minut : minut);
             //+":"+(secds<10 ? "0" + secds : secds);
        $("#publishTime").val(today);
}

function changeCategory(){
       var selectedId=$("#categoryId").val();
       d=dialog({
            url:'${base}/commerce/platStoreCategory/dataTree?selectedId='+selectedId, 
            title: '选择企业分类',
          //  background: '#EEE', // 背景色
            opacity: 0.05,  // 透明度
            width: 300,
            height: 350
          });   
          d.show();
}
function  doUploadLogo(){   
    // 上传方法
    $.upload({
        url: '${base}/commerce/platUploadfile/storeFileAdd',// 上传地址
        fileName: 'upfile',// 文件域名字
        params: {"fileTag":3}, // 其他表单数据
        accept:"image/*",
        dataType: 'json', // 上传完成后, 返回json, text
        onSend: function() {// 上传之前回调,return true表示可继续上传
            return true;
        },
        // 上传之后回调
        onComplate: function(data) {
        		if(data.state=='ERROR'){
                   tips(data.message);
               }
               else{
	               var imgname = data.url;
	               $("#logoPicPreview").html("<li class='fl ml10' data-type='1'>"
	                +"<div class='image-div'><a href='${base}/"+imgname+"' target='_black'><img class='pb5'  src='${base}/"+imgname+"' style='width:150px;height:150px;'></a></div>"
	                +"<div class='pt5'><input type='hidden' value='"+data.fileType+"'>"
	                +"<input type='button' class='select-btn ml10 fr' style='width:40px' onClick='deleteFile(this)' value='删除'></div></li>");        
	               $("#logoId").val(data.fileType);
	               $("#logoUrl").val(imgname);
	          }      
        }
    });
}   

function  doUpload(){
    // 最多5幅
    if($("#imglist li").length>=5){
        return ;
    }
       
    // 上传方法
    $.upload({
        url: '${base}/commerce/platUploadfile/storeFileAdd',// 上传地址
        fileName: 'upfile',// 文件域名字
        params: {"fileTag":2}, // 其他表单数据
        accept:"image/*",
        dataType: 'json', // 上传完成后, 返回json, text
        onSend: function() {// 上传之前回调,return true表示可继续上传
            return true;
        },
        // 上传之后回调
        onComplate: function(data) {
        	   if(data.state=='ERROR'){
                   tips(data.message);
               }
               else{
	               var imgname = data.url;
	                $("#imglist").parent().height(190);
	               $("#imglist").append("<li class='fl ml10' data-name='"+imgname+"'><div class='image-div'><a href='${base}/"+imgname+"' target='_black'><img class='pb5'  src='${base}/"+imgname
	               +"' style='width:150px;height:150px;'></a></div><div class='pt5'><input type='hidden' name='imageId' value='"
	                +data.fileType+"'><input name='isMain' type='button'class='fl' style='width:80px' onClick='setMain(this)' value='设为主图'>"
	                +"<input type='button' class='ml10 fr' style='width:40px' onClick='deleteFile(this)' value='删除'></div></li>")
              }
        }
    });
}

function setMain(param){
   var thisli=$(param).parent().parent();
   if(thisli.find("img:eq(0)").hasClass("mainImage")){
       $("#bannerId").val('');
       $("#bannerUrl").val('');
       thisli.find("img:eq(0)").removeClass("mainImage"); 
       thisli.find("input[name='isMain']").val("设为主图");
   }
   else{
       thisli.parent().find("input[name='isMain']").val("设为主图");
       thisli.parent().find("img").removeClass("mainImage");
       var fileId=thisli.find("input:eq(0)").attr("value");
       var fileUrl=thisli.attr("data-name");
       $("#bannerId").val(fileId);
       $("#bannerUrl").val(fileUrl);
       thisli.find("img:eq(0)").addClass("mainImage"); 
       thisli.find("input[name='isMain']").val("取消主图");
  }
}

  $(function() {
        // 保存
        $("#butSave").click(function(){  
        var content = UE.getEditor('myEditor')
                            .getContent()
                            .replace(/\[b\]([^\[]*?)\[\/b\]/igm, '<b>$1</b>')
                            .replace(/\[i\]([^\[]*?)\[\/i\]/igm, '<i>$1</i>')
                            .replace(/\[u\]([^\[]*?)\[\/u\]/igm, '<u>$1</u>')
                            .replace(/\[url=([^\]]*)\]([^\[]*?)\[\/url\]/igm, '<a href="$1">$2</a>')
                            .replace(/\[img\]([^\[]*?)\[\/img\]/igm, '<img src="$1" />');
            $("#content").val(content);                        
            $("#dataform").submit();          
         });

        var v = jQuery("#dataform").validate({
             submitHandler: function(form) {
                $(form).ajaxSubmit({
                    url:"${base}/commerce/platStore/"+$("#id").val()+"/update",
                    success: function(data){  
                        noty({
                          text:extendMessages(data).msg.message,
                          layout:"center",
                          timeout:2000,
                          callback:{
                             afterClose:function(){
                                          window.history.go(-1); 
                                        //  location.reload()
                                        }
                           }
                        });
                   }
                });
            }
       });
       $("#butCancel").click(function(){
            window.history.go(-1);           
          //window.location=document.referrer; 
       });     
  });
  
      
 function getProvince(param){
  var $thisNode=$(param).parent().parent();    
  var $country=$thisNode.find("select:eq(0)").val();
  if($country!=-1){
  $.ajax({
            url:"${base}/datacenter/selectAreas",
            data:{"uppid":$country,
                  "levelno":1
            },
            type:"POST",
            dataType:"json",
            success:function(json){
                var options_str = "";
                $thisNode.find("select:eq(1)").html("");
                options_str += "<option value='-1' >请选择地区</option>";
                $.each(json,function(i, item){
                        options_str += "<option value=\"" + item.id + "\" >" + item.name + "</option>";
                });
                
                $thisNode.find("select:eq(1)").append(options_str);
            },
            error:function(xhr, status){
                tips("error");
            }
    });
  
  }
}

function getCity(param){
      var $thisNode=$(param).parent().parent();    
      var $province=$thisNode.find("select:eq(1)").val();
      if($province!=-1){
      $.ajax({
                url:"${base}/datacenter/selectAreas",
                data:{"uppid":$province,
                      "levelno":2
                },
                type:"POST",
                dataType:"json",
                success:function(json){
                    var options_str = "";
                    $thisNode.find("select:eq(2)").html("");
                    options_str += "<option value='-1' >请选择城市</option>";
                    $.each(json,function(i, item){
                            options_str += "<option value=\"" + item.id + "\" >" + item.name + "</option>";
                    });
                    
                    $thisNode.find("select:eq(2)").append(options_str);
                },
                error:function(xhr, status){
                    tips("error");
                }
        });
      
      }
    }
function getDistrict(param){
      var $thisNode=$(param).parent().parent();    
      var $city=$thisNode.find("select:eq(2)").val();
      if($city!=-1){
      $.ajax({
                url:"${base}/datacenter/selectAreas",
                data:{"uppid":$city,
                      "levelno":3
                },
                type:"POST",
                dataType:"json",
                success:function(json){
                    var options_str = "";
                    $thisNode.find("select:eq(3)").html("");
                    options_str += "<option value='-1' >请选择区县</option>";
                    $.each(json,function(i, item){
                            options_str += "<option value=\"" + item.id + "\" >" + item.name + "</option>";
                    });
                    
                    $thisNode.find("select:eq(3)").append(options_str);
                },
                error:function(xhr, status){
                    tips("error");
                }
        });
      
      }
    }
    
function setContact()
{  
    if($("#eva_tab2").children().length==0){   
        $.ajax({
            type: "POST", //提交的类型 
            url:  "${base}/commerce/platStoreContact/contactEdit",//提交地址 
            data: $("#dataform").serializeArray(),//参数 
            //contentType: "application/json; charset=utf-8", 
            success: function(msg){//回调方法 
                        $("#eva_tab2").html(msg);
                    }
        });  
   }
  
}
</script>
</head>
<body>
    <form id="dataform" action="#" method="POST">
        <input type="hidden" name="categoryId" id="categoryId" value="${(bean.categoryId)!0}">
        <input type="hidden" name="id" id="id" value="${(bean.id)!1}">
        <input type="hidden" name="name" id="name" value="${(bean.name)!1}">
        <input type="hidden" name="ownerId" id="ownerId" value="${(bean.ownerId)!0}">
     [#--   <input type="hidden" name="page" id="nowpager" value="${page!1}"> --]
     
        <div class="right_top"><span class="pl20 f14">企业信息编辑</span></div>
        <div class="eva_content_top mt10" >
            <ul id="eva_all">
                <li><a tab="eva_tab1" class="eva_focus" href="javascript:void(0);">基本信息</a></li>
                <li><a tab="eva_tab2" class="white" href="javascript:void(0);" onclick="setContact();">联系方式</a></li>
            </ul>
        </div>
        <div id='eva_tab1' class="commerce_1 pb10 ml10 mt10 eva_tab">
            <table id="add_table" class="main_table">
               <tr>
                  <td class="tr w150"><span class="error">*</span>名称：</td>
                  <td class="pl10">${(bean.name)!''}</td>
               </tr>
                <tr>
                  <td class="tr w150"><span class="error">*</span>分类：</td>
                  <td class="pl10"><input type="text" class="required input_2" id="categoryName" name="categoryName" value="${(bean.categoryName)!''}" readonly="readonly">
                       <input type="button" class="select-btn" value="选择" onclick='changeCategory()'></td>
               </tr>
               <tr>
                  <td class="tr w150"><span class="error">*</span>类型：</td>
                  <td class="pl10"><td class="pl10"><input type='radio' value='0' name='type' [#if bean.type=0]checked='checked'[/#if]>公司
                                   <input type='radio' value='1' name='type' [#if bean.type=1]checked='checked'[/#if]>店铺
                  </td>
               </tr>
               <tr>
                   <td class="tr w150">状态：</td>
                   <td class="pl10"><select id="status" name="status">
                                        <option value="1" [#if (bean.status)==1]selected='selected'[/#if]>开启</option>
                                        <option value="0" [#if (bean.status)==0]selected='selected'[/#if]>关闭</option>
                                        <option value="2" [#if (bean.status)==2]selected='selected'[/#if]>审核中</option>
                         </select>
                   </td>
               </tr>
               <tr>
                  <td class="tr w150" style="vertical-align:top">LOGO：</td>
                  <td class="pl10">
                     <input type="hidden" name="logoId" id="logoId" value="${(bean.logoId)!}" >
                     <input type="hidden" name="logoUrl" id="logoUrl" value="${(bean.logoUrl)!''}" >
                     <input type="button" style="width: 100px;" class="select-btn"  onclick="doUploadLogo();" value="上传图片"/>
                     <span class="error">（注：上传图片大小不超过2M，最佳像素为150*150！）</span>               
                     <div class="mt10">
                        <ul id="logoPicPreview" class="grid" style="width:170px;">
                          [#if bean.logoUrl??]
                            <li class='fl ml10' data-name=''>
                               <div class='image-div'>
                                    <a href='${base}/${(bean.logoUrl)!}' target='_black'>
                                    <img src='${base}/${(bean.logoUrl)!}' style='width:150px;height:150px;'></a></div>
                               <div class='pt5'><input type='hidden' value='${(bean.logoId)!}'><input type='button' class='select-btn ml10 fr' style='width:40px' onClick='deleteFile(this)' value='删除'></div>
                            </li>
                          [/#if]
                        </ul>
                    </div>
                 </td>
               </tr>
               <tr>
                  <td class="tr w150">简介：</td>
                  <td class="pl10"><input type="text" class="input_2" style="width: 300px;" maxlength='60' id="description" name="description" value="${(bean.description)!''}">（60字以内）</td>
               </tr>
               <tr>
                  <td class="tr w150" style="vertical-align:top">介绍图片：</td>
                  <td class="pl10">
                     <input type="hidden" name="bannerId" id="bannerId" value="${(item.bannerId)!}" >
                     <input type="hidden" name="bannerUrl" id="bannerUrl" value="${(item.bannerUrl)!}" >
                     <input type="button" style="width: 100px;" class="select-btn"  onclick="doUpload();" value="上传图片"/>
                     <span class="error">（注：上传图片大小不超过2M，最佳像素为150*150！）</span>                
                     <div class="mt10">
                        <ul id="imglist" class="grid">
                        [#if images??]
                         [#list images as item]
                            <li class='fl ml10' data-name='${item.url}'>
                                <div class='image-div'><a href='${base}/${(item.url)!}' target='_black'>
                                                        <img [#if bean.bannerId??] [#if bean.bannerId==item.id] class='mainImage'[/#if] [/#if] src='${base}/${(item.url)!}' style='width:150px;height:150px;'></a></div>
                                <div class='pt5'><input type='hidden' name='imageId' value='${(item.id)!}'>
                                                <input name='isMain' type='button'class='fl' style='width:80px' onClick='setMain(this)' [#if bean.bannerId?exists && bean.bannerId==item.id] value='取消主图'[#else] value='设为主图'[/#if]>
                                                <input type='button' class='ml10 fr' style='width:40px' onClick='deleteFile(this)' value='删除'>  
                                </div>
                            </li>
                         [/#list]
                       [/#if]
                        </ul>
                     </div>
                  </td>
               </tr>
               <tr style="height:550px" >         
                  <td class="tr pt10  w150" style="vertical-align:top">详细介绍</td>
                  <td class="vt pt10 pl10"><textarea style="display:none"  id="content" name="content"></textarea>
                      <div class="editor">    
                           <script type="text/plain" id="myEditor">${(bean.content)!''}</script>     
                           <script type="text/plain" id="upload_ue"></script>
                      </div>
                  </td> 
               </tr>
               <tr>
                  <td class="tr w150">地址：</td><td class="pl10"><select name="addrCountryid" onchange="getProvince(this);">
                             <option value="" >请选择国家</option>
                             [#if areas??][#list areas as items]
                            <option value="${items.id}" [#if thisCountry??][#if thisCountry==items.id]selected="selected"[/#if][/#if]>${items.name}</option>
                            [/#list]
                            [/#if]
                        </select>
                            <select name="addrRegionid" onchange="getCity(this);">
                             <option value="" >请选择地区</option>
                             [#if thisRegions??][#list thisRegions as items]
                            <option value="${items.id}" [#if thisRegion??][#if thisRegion==items.id]selected="selected"[/#if][/#if]>${items.name}</option>
                            [/#list]
                            [/#if]
                        </select>
                        <select name="addrCityid" id="addrCityId" onchange="getDistrict(this);">
                          <option value="" >请选择城市</option>
                          [#if thisCities??][#list thisCities as items]
                            <option value="${items.id}" [#if thisCity??][#if thisCity==items.id]selected="selected"[/#if][/#if]>${items.name}</option>
                            [/#list]
                            [/#if]                      
                        </select>
                        <select name="addrDistrictid" id="addrDistrictId" >
                          <option value="" >请选择区县</option> 
                          [#if thisDistincts??][#list thisDistincts as items]
                            <option value="${items.id}" [#if bean.areaId??][#if bean.areaId==items.id]selected="selected"[/#if][/#if]>${items.name}</option>
                            [/#list]
                            [/#if]                     
                        </select></td>
               </tr>
               <tr>
                  <td class="tr w150">详细地址：</td>
                  <td class="pl10"><input type="text" class="input_2" style="width: 300px;"   id="address" name="address" value="${(bean.address)!''}"></td>
               </tr>
               
               <tr>   
                  <td class="tr w150 mt10" style="vertical-align:top">附件：</td>
                  <td class="pl10"><input type="button" style="width: 100px;"  class="select-btn" onclick="upFiles();" value="上传附件"/>
                      <ul id="filelist" class="grid">
                      [#if files??]
                       [#list files as item]
                        <li>
                            <input type='hidden' value='${(item.id)!0}' name='fileId'>
                            <a href="${base}/${(item.url)!}" target="_black">${(item.originalName)!''}</a>
                            <a href="#" onclick="deleteFile(this);">删除</a>
                        </li>
                    [/#list]
                    [/#if]
                      </ul>                      
                  </td>
               </tr>
            </table>
           <div class="pro-btn pt30">
              <div class="tc" colspan="2">
                    <input class="btn_2" type="button" id="butSave" value="提交">
                    <input class="btn_1 ml15" id="butCancel" type="button" value="取消">
              </div>
           </div>
      </div> 
      <div id='eva_tab2' class="commerce_1 pb10 ml10 mt10 eva_tab"> 
      </div>   
    </form>
</body>
</html>